package com.example.myapplication.test;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.R;
import com.example.myapplication.TimeTextView;

import java.util.List;


/**
 * 描述: { 拼团弹窗的Adapter }
 *
 * @GitHub： https://github.com/JamesYang1624
 * @email： ywzst30@163.com
 * @CreateDate: 2019/12/21 15:30
 * @Author JamesYang
 */
public class CourseFightAdapter extends RecyclerView.Adapter {


    private int type;
    private Context mContext;
    private List<Long> mList;

    public CourseFightAdapter(/*int type,*/ Context context, List<Long> list) {
        this.type = type;
        mContext = context;
        mList = list;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        return new CourseFightVerticalHolder(LayoutInflater.from(mContext).inflate(R.layout.item_course_fight_vertical, viewGroup, false));
//        if (type == 1) {
//        }
//        if (type == 2) {
//            return new CourseFightHriHorizontalHolder(LayoutInflater.from(mContext).inflate(R.layout.item_course_fight_horizontal, viewGroup, false));
//        }
//        return null;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) {
        CourseFightVerticalHolder holder = (CourseFightVerticalHolder) viewHolder;
        final Long aLong = mList.get(position);
        Log.i("CourseFightAdapter ", " aLong =" + aLong);
        TimeTextView timeTextView = holder.mTvFightTiming;
        //设置倒计时
        holder.mTvFightTiming.setTime(aLong);
        timeTextView.setNumRemain(1);
        final CountDownHandler mHandler = new CountDownHandler(timeTextView);
        mHandler.sendEmptyMessage(CountDownHandler.PAGE_COURSE_ORDER_DETAILS);
        holder.mTvGoFight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList == null ? 0 : mList.size();
    }

    class CourseFightVerticalHolder extends RecyclerView.ViewHolder {
        ImageView mIvLeaderIcon;
        TextView mTvFightDetails;
        TimeTextView mTvFightTiming;
        TextView mTvGoFight;

        public CourseFightVerticalHolder(@NonNull View itemView) {
            super(itemView);
            mIvLeaderIcon = itemView.findViewById(R.id.ivLeaderIcon);
            mTvFightDetails = itemView.findViewById(R.id.tvFightDetails);
            mTvFightTiming = itemView.findViewById(R.id.tvFightTiming);
            mTvGoFight = itemView.findViewById(R.id.tvGoFight);
        }
    }

//    class CourseFightHriHorizontalHolder extends RecyclerView.ViewHolder {
//        @BindView(R.id.ivFightUserIcon)
//        ImageView mIvFightUserIcon;
//
//        public CourseFightHriHorizontalHolder(@NonNull View itemView) {
//            super(itemView);
//            ButterKnife.bind(this, itemView);
//        }
//    }
}
